#!/usr/bin/python
# -*- coding: UTF-8 -*-

#~ The prime factors of 13195 are 5, 7, 13 and 29.
#~ 
#~ What is the largest prime factor of the number 600851475143 ?
#~ TODO : NOT SOLVED

import time
start = time.clock()

from mathlib import *

maximum = 600851475143
#~ maximum = 13195
d = 2
result = maximum

while ( d * d < result ) :
  if ( result % d == 0 and isprime(d) ) :
    print "d = "+str(d)
    print "result = "+str(result)
    result = result / d
    d -= 1
  if ( isprime( result ) ):
    break;
  d+=1

print result
print d

print "problem solved in ", (time.clock() - start), "s"
